/**
 * Created with IntelliJ IDEA.
 * Description:用泛型实现哈希桶
 * User: 39891
 * Date: 2025-04-10
 * Time: 19:41
 */
public class HashBuck2<V,M>{
    public static class Node<V,M>{
        public V key;
        public M val;
        public Node<V,M> node;

        public Node(V key, M val) {
            this.key = key;
            this.val = val;
        }
    }

    public Node<V,M>[] arr = new Node[10];
    public int usedSize;
    public void put(V key , M val){
        //1.通过哈希函数确定位置
        int hash = key.hashCode();
        int index = hash % arr.length;
        //2.判断是否出现重复的key，然后更新val
        //定义要插入的节点
        HashBuck2.Node node = new HashBuck2.Node(key,val);
        //已经是要插入数的那个位置了，遍历链表这里是
        Node<V,M> cur = arr[index];
        //如果出现重复的key，就更新val
        while(cur != null){
           //此处不能用=来比较两个V 类型的数据是否相同
            if (cur.key.equals(key)){
                cur.val = val;
                return;
            }
            cur = cur.next;
        }
}
